package com.hjx.other;

import java.util.Arrays;

/**
 * 翻转字符串，倒序输出字符串
 *
 *
 * @author houjinxin
 * @version 创建时间：2019/11/1.
 */
public class ReverseString {

    private static void printReverse(char [] str) {
        helper(0, str);
    }

    private static void helper(int index, char [] str) {
        if (str == null || index >= str.length) {
            return;
        }
        helper(index + 1, str);
        System.out.print(str[index]);
    }

    public static void main(String[] args) {
        String test = "hello";
//        printReverse(test.toCharArray());
        char[] chars = test.toCharArray();
        reverseString(chars);
        System.out.println(Arrays.toString(chars));
    }


    public static void reverseString(char[] s) {

        help2(s, 0);
    }

    public static void help2(char[] s, int index){
        if (index == s.length){
            return;
        }
        System.out.println(index);
        char temp = s[index++];
        help2(s, index);
        s[s.length - index] = temp;
    }
}
